package com.lm.orika.example;

import com.lm.orika.dto.UserDTO;
import com.lm.orika.entry.UserEntity;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;

public class OrikaExample {
    public static void main(String[] args) {
        // 创建 MapperFactory
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

        // 定义映射规则
        mapperFactory.classMap(UserDTO.class, UserEntity.class)
                .field("name", "fullName") // 映射字段
                .byDefault() // 自动映射其他相同名称的字段
                .register();

        // 获取 MapperFacade
        MapperFacade mapperFacade = mapperFactory.getMapperFacade();

        // 创建源对象
        UserDTO userDTO = new UserDTO();
        userDTO.setName("John");
        userDTO.setAge(30);

        // 执行映射
        UserEntity userEntity = mapperFacade.map(userDTO, UserEntity.class);

        // 打印映射结果
        System.out.println("Full Name: " + userEntity.getFullName());
        System.out.println("Age: " + userEntity.getAge());

        System.exit(0);
    }
}
